#pragma once


class CMenuMetrics
{
public:
	HTHEME  hTheme;                     // Theme handle
	HWND    hwndTheme;                  // Window handle used to 
	// generate hTheme

	MARGINS marPopupCheck;              // Popup check margins
	MARGINS marPopupCheckBackground;    // Popup check background 
	// margins
	MARGINS marPopupItem;               // Popup item margins
	MARGINS marPopupText;               // Popup text margins
	MARGINS marPopupAccelerator;        // Popup accelerator margins

	SIZE    sizePopupCheck;             // Popup check size metric
	SIZE    sizePopupSeparator;         // Popup separator size metric
	int     iPopupBorderSize;           // Popup border space between  
	// item text and accelerator
	int     iPopupBgBorderSize;         // Popup border space between 
	// item text and gutter

	int     cyMarCheckBackground;       // Additional amount of 
	// vertical space to add to 
	// checkbox

public:
	// Initialization / termination
	~CMenuMetrics();

	// Ensure ppMetrics is allocated and properly initialized.
	static HRESULT EnsureInitialized(__in HWND hwnd, __deref_inout  
		CMenuMetrics **ppMetrics);

	// Release any resources allocated by the object and setup object    
	// so that next EnsureInitialized() will initialize the object.
	void Flush();

	// Conversion functions
	POPUPITEMSTATES ToItemStateId(UINT uItemState);
	POPUPCHECKBACKGROUNDSTATES ToCheckBackgroundStateId(int iStateId);
	POPUPCHECKSTATES ToCheckStateId(UINT fType, int iStateId);

	void MeasureMenuItem(__inout MENUITEM *pmi, __inout 
		MEASUREITEMSTRUCT *pmis);
	void LayoutMenuItem(__in MENUITEM *pmi, __in DRAWITEMSTRUCT *pdis, 
		__out DRAWITEMMETRICS *pdim);

private:
	// Initialize the field members (on entry, hwndTheme is already set 
	// correctly).
	HRESULT Initialize();

	void ToMeasureSize(const SIZE *psizeDraw, const MARGINS 
		*pmargins, __out LPSIZE psizeMeasure);

	void ToDrawRect(LPCRECT prcMeasure, const MARGINS *pmargins, 
		__out LPRECT prcDraw);
};

